require_relative "../Expr"

# Expression for representing fractions
#
# @author Paul T.
class Calcula::Exprs::RatExpr < Calcula::Expr

  # @param top [Calcula::Token]  The token should have the type of NUM
  # @param bot [Calcula::Token]  The token should have the type of NUM
  def initialize(top, bot)
    @top = top
    @bot = bot
  end

  # @see Calcula::Expr#to_s
  # @param (see Calcula::Expr#to_s)
  # @return (see Calcula::Expr#to_s)
  def to_s(form: :src)
    case form
    when :src then
      "#{@top.text}//#{@bot.text}"
    when :tree then
      "(rat #{@top.text} #{@bot.text})"
    when :ruby then
      "Rational(#{@top.text}, #{@bot.text})"
    else
      nil
    end
  end

  # @see Calcula::Expr#children
  # @param (see Calcula::Expr#children)
  # @return (see Calcula::Expr#children)
  def children
    []
  end
end
